import request from '@/utils/request'

/**
 * 四级地址ID获取其子地址信息（id/code/name）
 * @param {obj} data 请求参数
 */
export function getAdminiDiv(data) {
  return request({
    url: `/call-center/api/v1/mscInfo/adminidiv`,
    method: 'GET',
    params: data
  })
}

/**
 * 办事处名称分页模糊办事处信息(id/code/name)
 * @param {obj} data 请求参数
 */
export function getOfficeRef(data) {
  return request({
    url: `/call-center/api/v1/mscInfo/office/ref/page`,
    method: 'GET',
    params: data
  })
}

/**
 * 根据电商订单ID获取电商订单明细
 * @param {string} orderId 电商订单ID
 */
export function getOrderDetail(orderId, sourceSystem) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/order/${orderId}?sourceSystem=${sourceSystem}`,
    method: 'GET'
  })
}

/**
 * 根据平台单号获取订单信息（同一平台单号不同电商单的公共信息）
 * @param {string} pcode 平台单号
 */
export function getOrderDetailPCode(data) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/order/pcode`,
    method: 'GET',
    params: data
  })
}

/**
 * 根据电商订单ID分页获取电商订单操作记录
 * @param {string} orderId 电商订单ID
 */
export function getOrderLog(orderId, data) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/order/${orderId}/logs`,
    method: 'GET',
    params: data
  })
}

/**
 * 根据电商订单ID获取电商订单跟踪信息
 * @param {string} orderId 电商订单ID
 */
export function getOrdereTracks(orderId) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/order/${orderId}/tracks`,
    method: 'GET'
  })
}

/**
 * 根据订单编号查询订单详细
 * @param {obj} data 查询参数
 */
export function getOrderList(params, data = {}) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/order/list`,
    method: 'POST',
    params: params,
    data
  })
}

/**
 * 分页获取四级地址配送表
 */
export function getRelationList() {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/relation`,
    method: 'POST'
  })
}

/**
 * 按经销商编码获取经销商所属办事处信息
 * @param {string} disCode 经销商编码
 */
export function getOfficeDetail(disCode, cnf = {}) {
  return request({
    url: `/call-center/api/v1/mscInfo/office/${disCode}`,
    method: 'GET',
    ...cnf,
    hiddenError: true
  })
}

/**
 * 获取产品图片
 * @param {string} productId 产品ID
 */
export function getProductImg(productId) {
  return request({
    url: `/call-center/api/v1/mscInfo/product/img/${productId}`,
    method: 'GET'
  })
}

/**
 * 经销商名称分页模糊经销商信息
 */
export function getCustomerRefPage(params, data) {
  return request({
    url: `/call-center/api/v1/mscInfo/dealer/page`,
    method: 'POST',
    params: params,
    data
  })
}

/**
 * 经销商ID获取其下门店信息
 * @param {string} customerIds 经销商ID
 */
export function getShopList(customerIds) {
  return request({
    url: `/call-center/api/v1/mscInfo/shop/list/${customerIds}`,
    method: 'GET'
  })
}

/**
 * 分页获取门店信息
 * @param {obj} data 查询参数
 */
export function getMscInfoShop(params, data = {}) {
  return request({
    url: `/call-center/api/v1/mscInfo/shop/page`,
    method: 'POST',
    params: params,
    data
  })
}

/**
 * 获取办事处下经销商信息
 * @param {string} officeCode
 */
export function getDealerInfo(data) {
  return request({
    url: `/call-center/api/v1/mscInfo/dealer/ref/page`,
    method: 'GET',
    params: data
  })
}

/**
 * 分页获取平台信息
 * @param {obj} data data
 */
export function getPlatformInfo(data) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/platform/page`,
    method: 'POST',
    params: data
  })
}

/**
 * 分页获取平台信息
 * @param {obj} data data
 */
export function getPlatformInfoB2CECO(data) {
  return request({
    url: `/select-service/api/v1/eco/platform/page`,
    method: 'POST',
    data: data
  })
}

/**
 * 分页获取店铺信息
 * @param {obj} data data
 */
export function getStoreInfo(data) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/store/page`,
    method: 'POST',
    params: data
  })
}

/**
 * 分页获取店铺信息 ECO及B2C获取店铺信息
 * @param {obj} data data
 */
export function getStoreInfoB2CECO(data) {
  return request({
    url: `/select-service/api/v1/eco/shop/page`,
    method: 'POST',
    data: data
  })
}

/**
 * 获取物流信息
 * @param {obj} data data
 */
export function getTmsDataInfo(data) {
  return request({
    url: `/call-center/api/v1/tmsDataInfo/track`,
    method: 'POST',
    data
  })
}
/** 财务外呼获取相关数据 */
export function getFinanceCallOutInfo(code) {
  return request({
    url: `/call-center/api/v1/mscInfo/accountContact/${code}`,
    method: 'GET'
  })
}

/**
 * ECO订单详情
 * @param {String} id 订单ID
 * */
export function fetchOrderDetail(id) {
  return request({
    url: `/call-center/api/v1/mscInfo/eco/order/${id}`,
    method: 'get'
  })
}

/**
 * 商品缺货预计出货时间查询
 * @param {String} orderNo 订单号
 * */
export function fetchOrderDeliveryShip(orderNo) {
  return request({
    url: `/call-center/api/v1/mscInfo/shipping/${orderNo}`,
    method: 'get'
  })
}

/**
 * 根据平台编码和平台订单号查询订单评价信息
 * @returns
 */
export function getOrderEvaluate(dcCode, platformCode) {
  return request({
    url: `/call-center/api/v1/mscInfo/b2c/order/appraise?sourceSystem=1&pcode=${dcCode}&platformCode=${platformCode}`,
    method: 'POST'
  })
}

/**
 * 查询产品信息
 * @param {String} productCode 产品编码
 */
export function getProductInfo(productCode) {
  return request({
    url: `/call-center/api/v1/mscInfo/product/${productCode}`,
    method: 'get'
  })
}

/* 根据用户查询所属业务组 */
export function getBusinessGroup(accountNo) {
  return request({
    url: `/call-center/api/v1/businessGroup/members/groups/${accountNo}`,
    method: 'get'
  })
}
/**
 * 根据订单查询 电商订单-检查订单的服务商信息
 * @param {*} ecOrder
 * @returns
 */
export function electronicCheck(ecOrder) {
  return request({
    url: `/call-center/api/v1/mscInfo/electronic/check/${ecOrder}`,
    method: 'GET'
  }).then(res => {
    if (res.code === '10002' || res.code === 10002) {
      return Promise.reject('接口异常!')
    }
    return res
  })
}
/**
 * 根据经销商编码获取经销商信息
 * @param {*} disCode
 * @returns
 */
export function getDisByCode(disCode) {
  const data = new FormData()
  data.append('pageFlag', false)
  const filtersRaw = [
    { id: 'code', property: 'code', value: disCode, operator: '=' }
  ]
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: `/api/v1/mscInfo/b2c/service/page`,
    method: 'POST',
    data
  }).then(res => {
    if (res.data.records.length > 0) {
      return res.data.records[0]
    }
    return Promise.reject(res)
  })
}
